Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

151
Vistas
Access __webpack_exports__ from a webpack bundle using "new Function(code)"

I'm looking for a way to access classes inside a compiled webpack bundle after using new Function() to execute the bundle.

For example, I have

export class TestClass {
   constructor() {
      console.log('Success');
   }
}

Which webpack compiles to:

/******/ (() => { // webpackBootstrap
/******/    "use strict";
   var __webpack_exports__ = {};
   // This entry need to be wrapped in an IIFE because it uses a non-standard name for the exports (exports).
   (() => {
      var exports = __webpack_exports__;
      /*!*********************!*\
        !*** ./src/test.ts ***!
        \*********************/

      Object.defineProperty(exports, "__esModule", ({ value: true }));
      exports.TestClass = void 0;
      class TestClass {
         constructor() {
            console.log('Success');
         }
      }
      exports.TestClass = TestClass;

   })();

   /******/
})()
   ;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7QUFBQSxNQUFhLFNBQVM7SUFDbkI7UUFDRyxPQUFPLENBQUMsR0FBRyxDQUFDLFNBQVMsQ0FBQyxDQUFDO0lBQzFCLENBQUM7Q0FDSDtBQUpELDhCQUlDIiwic291cmNlcyI6WyJ3ZWJwYWNrOi8vc3RyYXRlZ3kvc3JjL1VzZXJzL2FkbWluL2NvZGUvYm90bWFpbi9zdHJhdGVneS9zcmMvdGVzdC50cyJdLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgY2xhc3MgVGVzdENsYXNzIHtcbiAgIGNvbnN0cnVjdG9yKCkge1xuICAgICAgY29uc29sZS5sb2coJ1N1Y2Nlc3MnKTtcbiAgIH1cbn0iXSwibmFtZXMiOltdLCJzb3VyY2VSb290IjoiIn0=

If I load this bundle from the file system and execute it using new Function(), how can I then access TestClass?

I would like to do something like:

const code = await fs.readFile(path, 'utf8')
const rawModule = new Function(code)();

const instance = new rawModule.TestClass();

I basically need to access __webpack_exports__. Is there some webpack loader or other way I can do this?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda